package com.njust.controller.RequestMappingHandler;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/book")
public class BookController {


    @RequestMapping("/page")
    public String getPage(){
        return "resttest.jsp";
    }
    /**
      获得图书
     */
    @RequestMapping(value = "/{bid}", method = RequestMethod.GET)
    public String getBook(@PathVariable("bid")Integer id){
        System.out.println("查询到了" + id + "号图书");
        return "success.jsp";
    }

    /**
     * 添加图书
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public String addBook(){
        System.out.println("添加了新的图书");
        return "success.jsp";
    }

    /**
     * 删除图书
     * DELETE:不支持直接返回为jsp文件
     * @param id
     * @return
     */
    @RequestMapping(value = "/{bid}", method = RequestMethod.DELETE)
    public String deleteBook(@PathVariable("bid") Integer id){
        System.out.println("删除了" + id + "号图书");
        return "redirect:/first/hello";
    }

    /**
     * 更新图书
     * PUT:不支持直接返回为jsp文件
     * @param id
     * @return
     */
    @RequestMapping(value = "/{bid}", method = RequestMethod.PUT)
    public String updateBook(@PathVariable("bid") Integer id){
        System.out.println("更新了" + id + "号图书");
        return "redirect:/first/hello";
    }
}
